$(function () {

    let form = layui.form
    form.verify({
        nickname: [
            /^[\S]{1,10}$/,
            '用户名必须1到10个字符，且不能出现空格'
        ]
    });
    let layer = layui.layer
    initUserInfo()
    function initUserInfo() {
        axios({
            method: 'GET',
            url: '/my/userinfo',
        }).then(res => {
            if (res.data.status !== 0) {
                return layer.msg(res.data.message)
            }
            form.val('formUserInfo', res.data.data)
        })




    }


    $('#btnRest').on('click', function (e) {
        e.preventDefault()
        initUserInfo()

    })


    $('form').on('submit', function (e) {
        e.preventDefault()
        axios({
            method: 'POST',
            url: '/my/userinfo',
            data: $(this).serialize()

        }).then(res => {
            console.log(res)
            if (res.data.status) {
                return layer.msg(res.data.message)
            }
            layer.msg("恭喜您,修改成功")
            window.parent.getUserInfo()
        })



    })




})